rom config.log_config import AntLogger
from dao.stock_found_das import StockFoundDas

class StockFoundService:
    @staticmethod
    def createStrategyResult(data):
        '''创建策略记录'''
        AntLogger.info('开始创建策略记录')
        try:
            result = StockFoundDas.create_strategy_result(
                stock_code=data['stockCode'],
                stock_name=data['stockName'],
                stock_plates=data['stockPlates'],
                total_score=data['totalScore'],
                risk_level=data['riskLevel'],
                focus_level=data['focusLevel'],
                latest_price=data.get('latestPrice'),
                risk_assessments=data['riskAssessments'],
                strategy_code=data['strategyCode']
            )
            AntLogger.info('策略记录创建完成')
            return result
        except Exception as e:
            AntLogger.error(f'创建策略记录异常: {e}')
            return None

    @staticmethod
    def updateStrategyResult(id, updates):
        '''更新策略记录'''
        AntLogger.info(f'开始更新策略记录ID:{id}')
        return StockFoundDas.update_strategy_result(id, updates)

    @staticmethod
    def deleteStrategyResult(stockCode):
        '''删除策略记录'''
        AntLogger.warning(f'准备删除股票代码:{stockCode}的记录')
        return StockFoundDas.delete_strategy_result(stockCode)

    @staticmethod
    def getStrategyDetail(id):
        '''获取策略详情'''
        AntLogger.debug(f'查询策略详情ID:{id}')
        return StockFoundDas.get_strategy_by_id(id)